//SPU接口
import request from '@/utils/request'
import type {
  SpuResponseData,
  AllTradeMark,
  SpuImageResponseData,
  SpuSaleAttrResponseData,
  HasSaleAttrResponseData,
  SpuInfo,
  SkuData,
  SkuResponseData,
} from '@/api/product/spu/type.ts'
enum SPU_API {
  //获取SPU列表
  SPU_PAGE_URL = '/admin/product',
  //保存SPU
  SAVE_SPU_URL = '/admin/product/saveSpuInfo',
  //更新SPU
  UPDATE_SPU_URL = '/admin/product/updateSpuInfo',
  //获取所有销售属性列表
  BASE_SALE_ATTR_LIST_URL = '/admin/product/baseSaleAttrList',
  //删除SPU
  DELETE_SPU_URL = '/admin/product/deleteSpu',
  //获取全部品牌
  ALL_BRAND_URL = '/admin/product/baseTrademark/getTrademarkList',
  //获取某个SPU下全部图片数据接口
  SPU_IMAGE_URL = '/admin/product/spuImageList',
  //获取SPU销售属性
  SPU_SALE_ATTR_URL = '/admin/product/spuSaleAttrList',

  //添加SKU
  ADD_SKU_URL = '/admin/product/saveSkuInfo',

  //根据SPU获取SKU
  SPU_SKU_URL = '/admin/product/findBySpuId',
  //删除SKU
  DELETE_SKU_URL = '/admin/product/deleteSku',
}
export const reqSpuPageList = (
  page: number,
  limit: number,
  category3Id: number | string,
) =>
  request.get<any, SpuResponseData>(
    SPU_API.SPU_PAGE_URL + `/${page}/${limit}?category3Id=${category3Id}`,
  )
//获取全部品牌
export const reqAllBrand = () =>
  request.get<any, AllTradeMark>(SPU_API.ALL_BRAND_URL)
//获取某个SPU下全部图片数据接口
export const reqGetSpuImageList = (spuId: number) =>
  request.get<any, SpuImageResponseData>(SPU_API.SPU_IMAGE_URL + `/${spuId}`)
//获取SPU销售属性
export const reqGetSpuSaleAttrList = (spuId: number) =>
  request.get<any, SpuSaleAttrResponseData>(
    SPU_API.SPU_SALE_ATTR_URL + `/${spuId}`,
  )
//获取所有销售属性列表
export const reqBaseSaleAttrList = () =>
  request.get<any, HasSaleAttrResponseData>(SPU_API.BASE_SALE_ATTR_LIST_URL)
//保存SPU
export const reqAddOrUpdateSpu = (data: SpuInfo) => {
  if (data.id) {
    return request.post<any, any>(SPU_API.UPDATE_SPU_URL, data)
  }
  return request.post<any, any>(SPU_API.SAVE_SPU_URL, data)
}
//删除SPU
export const reqDeleteSpu = (spuId: number | string) =>
  request.delete<any, any>(SPU_API.DELETE_SPU_URL + `/${spuId}`)
//sku相关接口======================
//添加SKU
export const reqAddSku = (data: SkuData) =>
  request.post<any, any>(SPU_API.ADD_SKU_URL, data)

//根据SPU获取SKU
export const reqGetSkuList = (spuId: number) =>
  request.get<any, SkuResponseData>(SPU_API.SPU_SKU_URL + `/${spuId}`)
//删除SKU
export const reqDeleteSku = (skuId: number) =>
  request.delete<any, any>(SPU_API.DELETE_SKU_URL + `/${skuId}`)
